package dao;

import java.util.ArrayList;

import org.hibernate.Session;


import metier.Region;

public class DAORegionHib extends DAOHibernate implements DAORegion {

	@Override
	public Region get(int id) throws Exception {
		Region	region = null;
		Session	session = connect();		
		region = (Region) session.get(Region.class, id);	
		close(session);
		return region;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<Region> loadAll() throws Exception {
		ArrayList<Region>	tab = null;
		Session session = connect();
		
		tab = (ArrayList<Region>) session.createQuery("FROM Region")
				.list();
		
		close(session);
		return tab;
	}

	@Override
	public void save(Region region) throws Exception {
		Session	session = connect();
		
		session.save(region);
		
		close(session);	
		
	}

	@Override
	public void saveOrupdate(Region region) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Region region) throws Exception {
		Session	session = connect();
		
		session.delete(region);
		region.setId_region(-1);
		
		close(session);
		
	}

	@Override
	public void update(Region region) throws Exception {
		Session	session = connect();
		
		session.update(region);
		
		close(session);
		
		
	}
	
	
	
	

}
